<?php

/**
 * news actions.
 *
 * @package    sf_sandbox
 * @subpackage news
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class newsActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeAdd(sfWebRequest $request)
  {
  	$this->setDecorator();
    $this->form = new Type10Form();
    
  	 if ($request->isMethod('post'))

    {

      $this->form->bind($request->getParameter('material'),$request->getFiles('material'));
      if ($this->form->isValid())
      {
      	
        $this->form->save();
        $this->redirect('@news_list');
       
      }

    }
    
  }
  
  
  
  public function executeShow(sfWebRequest $request)
  {
  	if(sfConfig::get('app_lang_news')=='en') $this->getUser()->setCulture('en');
  	$this->setDecorator();
  	$this->news = MaterialPeer::retrieveByPK($request->getParameter('id'));
  	$this->forward404Unless($this->news);
  	
    ////Устанавливаем META ТЕГИ
	$this->getResponse()->addMeta('title', $this->news->getSeoItitle());
	$this->getResponse()->addMeta('keywords', $this->news->getSeoIkeyword());
	$this->getResponse()->addMeta('description', $this->news->getSeoIdescription());
	//// 
 	

  }
  
  public function executeEdit(sfWebRequest $request)
  {
  	$this->setDecorator();
  	$this->news = MaterialPeer::retrieveByPK($request->getParameter('id'));
  	$this->forward404Unless($this->news);
    $this->form = new Type10Form($this->news);
    
  	 if ($request->isMethod('post'))

    {

      $this->form->bind($request->getParameter('material'),$request->getFiles('material'));
      if ($this->form->isValid())
      {
      	
        $this->form->save();
        $this->redirect('@news_list'); 
       
      }

    }
    
  }
  
  
  public function executeDelete(sfWebRequest $request)
  {
  	$this->news = MaterialPeer::retrieveByPK($request->getParameter('id'));
  	$this->forward404Unless($this->news);
  	$this->news->delete();
  	
  }
  
  public function executeList(sfWebRequest $request)
  {
  	if(sfConfig::get('app_lang_news')=='en') $this->getUser()->setCulture('en');
  	$this->setDecorator();
  	
  }
  
	public function setDecorator()
	{
		
		$module = $this->getRequest()->getParameter('module');
		$action = $this->getRequest()->getParameter('action');
		
		$path_layout = sfConfig::get('sf_app_template_dir').'/layouts/'.sfConfig::get('app_name').'/'.$module.'.php';
		$path_template = sfConfig::get('sf_app_module_dir').'/'.$module.'/templates/'.sfConfig::get('app_name').'/'.$action.'Success.php';
		if(file_exists($path_layout))
		{ $l = 'layouts/'.sfConfig::get('app_name').'/'.$module; }
		else
		{ $l = sfConfig::get('app_name').'_layout'; }
		if(file_exists($path_template))
		{ $t = sfConfig::get('app_name').'/'.$action; }
		else
		{ $t = $action; }
			
	/*
     * Установка layout
     */	
			$this->setLayout ( $l );
		
     /*
     *  Устанавливаем шаблон
     */
		
			$this->setTemplate ( $t );
	}
  
}
